class AIAssistant:
    def __init__(self, id, name, type, version, online, score):
        self.id = id
        self.name = name
        self.type = type
        self.version = version
        self.online = online
        self.score = score

    def display_info(self):
        status = "在线" if self.online else "离线"
        return f"ID: {self.id}, 名称: {self.name}, 类型: {self.type}, 版本: {self.version}, 状态: {status}, 能力评分: {self.score}"


class AIManager:
    def __init__(self):
        # 使用列表来存储AI助手
        self.assistants = []
        self.init_data()

    def init_data(self):
        assistant1 = AIAssistant(101, "小智", "语音助手", "v1.2", True, 85)
        assistant2 = AIAssistant(102, "文小助", "文本助手", "v2.0", True, 92)
        assistant3 = AIAssistant(103, "图灵", "图像助手", "v1.5", False, 88)
        assistant4 = AIAssistant(104, "数小析", "数据分析助手", "v1.0", True, 79)
        assistant5 = AIAssistant(105, "翻译精灵", "翻译助手", "v2.1", False, 95)

        self.assistants.append(assistant1)
        self.assistants.append(assistant2)
        self.assistants.append(assistant3)
        self.assistants.append(assistant4)
        self.assistants.append(assistant5)

    def show_menu(self):
        """显示主菜单"""
        print("\n" + "=" * 10 + " AI助手管理器 " + "=" * 10)
        print("1. 查看所有AI助手列表")
        print("2. 根据ID查询助手详情")
        print("3. 添加新的AI助手")
        print("4. 修改助手信息")
        print("5. 删除AI助手")
        print("6. 启动AI助手服务")
        print("7. 停止AI助手服务")
        print("8. 分配任务")
        print("9. 显示统计信息")
        print("0. 退出系统")
        print("=" * 35)

    def show_all_assistants(self):
        """显示所有AI助手"""
        print("\n所有AI助手列表：")
        if len(self.assistants) == 0:
            print("暂无AI助手")
            return

        for i, assistant in enumerate(self.assistants, 1):
            print(f"{i}. {assistant.display_info()}")

    def search_assistant(self):
        """根据ID查找助手"""
        try:
            id_input = int(input("请输入要查询的AI助手ID: "))
        except:
            print("请输入有效的数字ID！")
            return

        for assistant in self.assistants:
            if assistant.id == id_input:
                print("查询结果:", assistant.display_info())
                return

        print(f"未找到ID为 {id_input} 的AI助手")

    def add_assistant(self):
        """添加新的AI助手"""
        print("\n添加新AI助手")

        try:
            new_id = int(input("请输入ID: "))
            new_name = input("请输入名称: ")
            new_type = input("请输入类型: ")
            new_version = input("请输入版本号: ")

            online_input = input("是否在线？(1-是, 0-否): ")
            new_online = (online_input == "1")

            new_score = int(input("请输入能力评分(0-100): "))

            for assistant in self.assistants:
                if assistant.id == new_id:
                    print("该ID已存在！")
                    return

            new_assistant = AIAssistant(new_id, new_name, new_type, new_version, new_online, new_score)

            self.assistants.append(new_assistant)
            print(f"助手【{new_name}】添加成功！")

        except:
            print("输入有误，请重新操作")

    def modify_assistant(self):
        """修改助手信息"""
        try:
            id_input = int(input("请输入要修改的AI助手ID: "))
        except:
            print("请输入有效的数字ID！")
            return

        for assistant in self.assistants:
            if assistant.id == id_input:
                print("当前信息:", assistant.display_info())
                print("\n可修改属性: 名称(name), 类型(type), 版本(version), 在线状态(online), 评分(score)")

                modify_input = input("请输入要修改的属性和新值（格式：属性名 新值）: ").split()

                if len(modify_input) < 2:
                    print("输入格式错误")
                    return

                attribute = modify_input[0]
                new_value = " ".join(modify_input[1:])  # 处理可能包含空格的值

                if attribute == "name":
                    assistant.name = new_value
                elif attribute == "type":
                    assistant.type = new_value
                elif attribute == "version":
                    assistant.version = new_value
                elif attribute == "online":
                    assistant.online = (new_value == "1" or new_value.lower() == "true")
                elif attribute == "score":
                    try:
                        assistant.score = int(new_value)
                    except:
                        print("评分必须是数字")
                        return
                else:
                    print("无效的属性名")
                    return

                print(f"助手【{id_input}】修改成功！")
                return

        print(f"未找到ID为 {id_input} 的AI助手")

    def delete_assistant(self):
        """删除AI助手"""
        try:
            id_input = int(input("请输入要删除的AI助手ID: "))
        except:
            print("请输入有效的数字ID！")
            return

        for i, assistant in enumerate(self.assistants):
            if assistant.id == id_input:
                deleted_name = assistant.name
                del self.assistants[i]
                print(f"助手【{deleted_name}】已删除")
                return

        print(f"未找到ID为 {id_input} 的AI助手")

    def start_service(self):
        """启动AI助手服务"""
        try:
            id_input = int(input("请输入要启动的AI助手ID: "))
        except:
            print("请输入有效的数字ID！")
            return

        for assistant in self.assistants:
            if assistant.id == id_input:
                if assistant.online:
                    print(f"助手【{assistant.name}】已在运行")
                else:
                    assistant.online = True
                    print(f"助手【{assistant.name}】已启动")
                return

        print(f"未找到ID为 {id_input} 的AI助手")

    def stop_service(self):
        """停止AI助手服务"""
        try:
            id_input = int(input("请输入要停止的AI助手ID: "))
        except:
            print("请输入有效的数字ID！")
            return

        for assistant in self.assistants:
            if assistant.id == id_input:
                if not assistant.online:
                    print(f"助手【{assistant.name}】已处于停止状态")
                else:
                    assistant.online = False
                    print(f"助手【{assistant.name}】已停止")
                return

        print(f"未找到ID为 {id_input} 的AI助手")

    def assign_task(self):
        """分配任务给AI助手"""
        try:
            id_input = int(input("请输入目标AI助手ID: "))
        except:
            print("请输入有效的数字ID！")
            return

        task = input("请输入任务内容: ")

        for assistant in self.assistants:
            if assistant.id == id_input:
                if assistant.online:
                    print(f"{assistant.name} 正在执行任务: {task}")
                else:
                    print(f"{assistant.name} 当前离线，无法执行任务")
                return

        print(f"未找到ID为 {id_input} 的AI助手")

    def show_statistics(self):
        """显示统计信息"""
        if len(self.assistants) == 0:
            print("暂无AI助手数据")
            return

        total = len(self.assistants)
        online_count = 0
        total_score = 0

        for assistant in self.assistants:
            if assistant.online:
                online_count += 1
            total_score += assistant.score

        offline_count = total - online_count
        average_score = total_score / total

        print("\n系统统计信息：")
        print(f"总助手数: {total}")
        print(f"在线助手数: {online_count}")
        print(f"离线助手数: {offline_count}")
        print(f"平均能力评分: {average_score:.2f}")

    def run(self):
        """运行AI助手管理器"""
        print("欢迎使用 AI助手管理器 v1.0")

        while True:
            self.show_menu()
            choice = input("请选择操作: ")

            if choice == "1":
                self.show_all_assistants()
            elif choice == "2":
                self.search_assistant()
            elif choice == "3":
                self.add_assistant()
            elif choice == "4":
                self.modify_assistant()
            elif choice == "5":
                self.delete_assistant()
            elif choice == "6":
                self.start_service()
            elif choice == "7":
                self.stop_service()
            elif choice == "8":
                self.assign_task()
            elif choice == "9":
                self.show_statistics()
            elif choice == "0":
                print("感谢使用AI助手管理器，再见！")
                break
            else:
                print("无效的选择，请重新输入！")

if __name__ == "__main__":
    manager = AIManager()
    manager.run()